On PBX, make sure the kamitserviceuser creads were created, including visudo command.
Log in as KamitServiceUser on ERX
su kamitserviceusercreate a ~/scripts folder
mkdir ~/scriptsinside ~/scripts folder, create a file called “
IPMonitor.sh”
touch ~/scripts/IPMonitor.shMake the script exicutable
sudo chmod +x ~/scripts/IPMonitor.shEdit the script
nano ~/scripts/IPMonitor.shAdd the following infomation: (Change both vPBXIP, vLOCATION)
#!/bin/bash
IPNow=$(curl -s ifconfig.me)
LOGFILE="/home/kamitserviceuser/scripts/IPMonitor.log"
vLOCATION="Axis Post Falls"
vPBXIP="216.128.182.136"
if test -f "$LOGFILE"; then
echo "Valid log file found."
else
echo "New Log File - $(date +%F-%T)" >$LOGFILE
fi
if ssh kamitserviceuser@$vPBXIP "sudo iptables -nvL | grep -q $IPNow"; then
echo "IP found ($IPNow), No Change - $(date +%F-%T)" >>$LOGFILE
else
echo "Change - $(date +%F-%T)" >>$LOGFILE
echo " Old IP: $(cat $FILE)">>$LOGFILE
echo " New IP: $IPNow ">>$LOGFILE
echo " Updating PBX iptables with rule comment: $vLOCATION - '$(date +%F-%T)">>$LOGFILE
ssh kamitserviceuser@$vPBXIP "sudo iptables -I INPUT 1 -s $IPNow -j ACCEPT -m comment --comment '$vLOCATION - '$(date +%F-%T)"
fiAdd the script to crontab
crontab -eAdd this entry
*/3 * * * * /home/kamitserviceuser/scripts/IPMonitor.sh